package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo {
    public static void main(String[] args) {
        Collection<String> c=new ArrayList<>();
        c.add("one");
        c.add("#");
        c.add("two");
        c.add("#");
        c.add("three");
        System.out.println(c);
        Iterator<String> it = c.iterator();
        while(it.hasNext())
        {
            String s = it.next();
            System.out.print(s);
            if("#".equals(s))
                it.remove();
        }
        System.out.println(c);
    }
}
